package com.stylefeng.guns.modular.lb.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.SysType;
import com.stylefeng.guns.modular.lb.service.ISysTypeService;

/**
 * lb控制器
 *
 * @author fengshuonan
 * @Date 2019-06-05 15:03:39
 */
@Controller
@RequestMapping("/sysType")
public class SysTypeController extends BaseController {

    private String PREFIX = "/lb/sysType/";

    @Autowired
    private ISysTypeService sysTypeService;

    /**
     * 跳转到lb首页
     */
    @RequestMapping("index")
    public String index() {
        return PREFIX + "sysType.html";
    }

    /**
     * 跳转到添加lb
     */
    @RequestMapping("/sysType_add")
    public String sysTypeAdd() {
        return PREFIX + "sysType_add.html";
    }

    /**
     * 跳转到修改lb
     */
    @RequestMapping("/sysType_update/{sysTypeId}")
    public String sysTypeUpdate(@PathVariable Integer sysTypeId, Model model) {
        SysType sysType = sysTypeService.selectById(sysTypeId);
        model.addAttribute("item",sysType);
        LogObjectHolder.me().set(sysType);
        return PREFIX + "sysType_edit.html";
    }

    /**
     * 获取lb列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return sysTypeService.selectList(null);
    }

    /**
     * 新增lb
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SysType sysType) {
        sysTypeService.insert(sysType);
        return SUCCESS_TIP;
    }

    /**
     * 删除lb
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sysTypeId) {
        sysTypeService.deleteById(sysTypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改lb
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SysType sysType) {
        sysTypeService.updateById(sysType);
        return SUCCESS_TIP;
    }

    /**
     * lb详情
     */
    @RequestMapping(value = "/detail/{sysTypeId}")
    @ResponseBody
    public Object detail(@PathVariable("sysTypeId") Integer sysTypeId) {
        return sysTypeService.selectById(sysTypeId);
    }
}
